package com.glodon.spring.serviceImp;

import com.alibaba.fastjson.JSON;
import com.glodon.spring.dao.BulletinDao;
import com.glodon.spring.enty.BulletinEntity;
import com.glodon.spring.service.BulletinService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * Created by Administrator on 2017-5-3.
 */
@Service
public class BulletinServiceImpl implements BulletinService {

    private static final Logger log = LoggerFactory.getLogger(BulletinServiceImpl.class);

    @Autowired
    private BulletinDao bulletinDao;

    @Override
    public List<BulletinEntity> query() {
        return bulletinDao.query();
    }

    @Override
    public List<LinkedHashMap<String, Object>> queryToMap() {
        return bulletinDao.queryToMap();
    }

    /**
     * 从MQ取数据
     *
     * @param bullentinEntity
     */
    @Transactional
    @Override
    public void accessMsg(String bullentinEntity) {
        log.warn("从消息队列进入处理函数..." );
        BulletinEntity bulletinEntity = JSON.parseObject(bullentinEntity, BulletinEntity.class);

        if (bullentinEntity != null) {
            log.info("从消息队列返回的实体对象：{}", bullentinEntity.toString());
        }

    }

    @Override
    public BulletinEntity queryById(String id) {
        return this.bulletinDao.queryById(id);
    }
}
